/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.uch.syscom.hibernateSpringDao;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import pe.edu.uch.syscom.mapping.TbMenu;
import pe.edu.uch.syscom.mapping.TbMenuRol;
import pe.edu.uch.syscom.mapping.TbUsuario;

/**
 *
 * @author Jose Tejada
 */
public class HSMenuDAOImpl extends HibernateDaoSupport implements HSMenuDAO {

    public List<TbMenu> listarMenuPorUsuario( TbUsuario usuario ) {
        TbMenuRol tbMenuRol;
        Iterator<TbMenuRol> it;
        List<Integer> lstMenuIds;
        List<TbMenu> lstMenuPorUsuario = null;

        try {

            lstMenuIds = new ArrayList<Integer>();
            
            it = usuario.getTbRol().getTbMenuRols().iterator();

            while ( it.hasNext() ) {
                tbMenuRol = it.next();
                lstMenuIds.add( tbMenuRol.getTbMenu().getActivo() );
            }

            lstMenuPorUsuario = this.getSession().
                    createCriteria( TbMenu.class ).
                    add( Restrictions.eq( "activo", 1 ) ).
//                    add( Restrictions.in( "idMenu", ) ).
                    list();
        } catch ( Exception ex ) {
        }

        return lstMenuPorUsuario;
    }
}
